.class public final Lcom/burstly/lib/currency/request/CurrencyRequester;
.super Ljava/lang/Object;
.source "CurrencyRequester.java"


# static fields
.field private static final LOG:Lcom/burstly/lib/util/LoggerExt; = null

.field private static final NANOS_IN_SEC:I = 0x3b9aca00

.field private static final TAG:Ljava/lang/String; = null

.field private static final THROTTLE_INTERVAL:I = 0xa

.field private static final THROTTLE_MAP:Ljava/util/Map;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/Long;",
            ">;"
        }
    .end annotation
.end field


# instance fields
.field mExecutor:Ljava/util/concurrent/Executor;

.field final mListeners:Ljava/util/List;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/List",
            "<",
            "Lcom/burstly/lib/feature/currency/ICurrencyListener;",
            ">;"
        }
    .end annotation
.end field

.field final mResetLock:Ljava/util/concurrent/locks/Lock;

.field final mResetLockCondition:Ljava/util/concurrent/locks/Condition;

.field final mUIHandler:Landroid/os/Handler;


# direct methods
.method static constructor <clinit>()V
    .locals 2

    .prologue
    .line 56
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/currency/request/CurrencyRequester;->LOG:Lcom/burstly/lib/util/LoggerExt;

    .line 61
    const-class v0, Lcom/burstly/lib/currency/request/CurrencyRequester;

    invoke-virtual {v0}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/currency/request/CurrencyRequester;->TAG:Ljava/lang/String;

    .line 66
    new-instance v0, Ljava/util/HashMap;

    const/4 v1, 0x5

    invoke-direct {v0, v1}, Ljava/util/HashMap;-><init>(I)V

    sput-object v0, Lcom/burstly/lib/currency/request/CurrencyRequester;->THROTTLE_MAP:Ljava/util/Map;

    return-void
.end method

.method public constructor <init>(Ljava/util/List;)V
    .locals 2
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/List",
            "<",
            "Lcom/burstly/lib/feature/currency/ICurrencyListener;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 98
    .local p1, listeners:Ljava/util/List;,"Ljava/util/List<Lcom/burstly/lib/feature/currency/ICurrencyListener;>;"
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 71
    new-instance v0, Ljava/util/concurrent/locks/ReentrantLock;

    invoke-direct {v0}, Ljava/util/concurrent/locks/ReentrantLock;-><init>()V

    iput-object v0, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mResetLock:Ljava/util/concurrent/locks/Lock;

    .line 76
    iget-object v0, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mResetLock:Ljava/util/concurrent/locks/Lock;

    invoke-interface {v0}, Ljava/util/concurrent/locks/Lock;->newCondition()Ljava/util/concurrent/locks/Condition;

    move-result-object v0

    iput-object v0, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mResetLockCondition:Ljava/util/concurrent/locks/Condition;

    .line 81
    invoke-static {}, Ljava/util/concurrent/Executors;->newSingleThreadExecutor()Ljava/util/concurrent/ExecutorService;

    move-result-object v0

    iput-object v0, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mExecutor:Ljava/util/concurrent/Executor;

    .line 91
    new-instance v0, Landroid/os/Handler;

    invoke-static {}, Landroid/os/Looper;->getMainLooper()Landroid/os/Looper;

    move-result-object v1

    invoke-direct {v0, v1}, Landroid/os/Handler;-><init>(Landroid/os/Looper;)V

    iput-object v0, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mUIHandler:Landroid/os/Handler;

    .line 99
    iput-object p1, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mListeners:Ljava/util/List;

    .line 100
    return-void
.end method

.method private static declared-synchronized isThrottled(Lcom/burstly/lib/currency/AccountInfo;)Z
    .locals 13
    .parameter "accInfo"

    .prologue
    const/4 v7, 0x1

    const/4 v6, 0x0

    .line 221
    const-class v8, Lcom/burstly/lib/currency/request/CurrencyRequester;

    monitor-enter v8

    :try_start_0
    new-instance v9, Ljava/lang/StringBuilder;

    invoke-direct {v9}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {p0}, Lcom/burstly/lib/currency/AccountInfo;->getUserId()Ljava/lang/String;

    move-result-object v10

    invoke-virtual {v9, v10}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v9

    invoke-virtual {p0}, Lcom/burstly/lib/currency/AccountInfo;->getPubId()Ljava/lang/String;

    move-result-object v10

    invoke-virtual {v9, v10}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v9

    invoke-virtual {v9}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    .line 222
    .local v0, key:Ljava/lang/String;
    sget-object v9, Lcom/burstly/lib/currency/request/CurrencyRequester;->THROTTLE_MAP:Ljava/util/Map;

    invoke-interface {v9, v0}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v5

    check-cast v5, Ljava/lang/Long;

    .line 223
    .local v5, requestTime:Ljava/lang/Long;
    if-nez v5, :cond_0

    .line 224
    sget-object v7, Lcom/burstly/lib/currency/request/CurrencyRequester;->THROTTLE_MAP:Ljava/util/Map;

    invoke-static {}, Ljava/lang/System;->nanoTime()J

    move-result-wide v9

    invoke-static {v9, v10}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v9

    invoke-interface {v7, v0, v9}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 234
    :goto_0
    monitor-exit v8

    return v6

    .line 227
    :cond_0
    :try_start_1
    invoke-static {}, Ljava/lang/System;->nanoTime()J

    move-result-wide v1

    .line 228
    .local v1, now:J
    invoke-virtual {v5}, Ljava/lang/Long;->longValue()J

    move-result-wide v9

    sub-long v9, v1, v9

    const-wide/32 v11, 0x3b9aca00

    div-long v3, v9, v11

    .line 229
    .local v3, passed:J
    const-wide/16 v9, 0xa

    cmp-long v9, v3, v9

    if-lez v9, :cond_1

    .line 230
    sget-object v7, Lcom/burstly/lib/currency/request/CurrencyRequester;->THROTTLE_MAP:Ljava/util/Map;

    invoke-interface {v7, v0}, Ljava/util/Map;->remove(Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_0

    .line 221
    .end local v0           #key:Ljava/lang/String;
    .end local v1           #now:J
    .end local v3           #passed:J
    .end local v5           #requestTime:Ljava/lang/Long;
    :catchall_0
    move-exception v6

    monitor-exit v8

    throw v6

    .line 233
    .restart local v0       #key:Ljava/lang/String;
    .restart local v1       #now:J
    .restart local v3       #passed:J
    .restart local v5       #requestTime:Ljava/lang/Long;
    :cond_1
    :try_start_2
    sget-object v6, Lcom/burstly/lib/currency/request/CurrencyRequester;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v9, Lcom/burstly/lib/currency/request/CurrencyRequester;->TAG:Ljava/lang/String;

    const-string v10, "Update balance request for {0} user is throttled!"

    const/4 v11, 0x1

    new-array v11, v11, [Ljava/lang/Object;

    const/4 v12, 0x0

    aput-object p0, v11, v12

    invoke-virtual {v6, v9, v10, v11}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    move v6, v7

    .line 234
    goto :goto_0
.end method

.method private notifyListeners(Ljava/util/Map;Z)V
    .locals 5
    .parameter
    .parameter "succeeded"
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Lcom/burstly/lib/currency/BalanceUpdateInfo;",
            ">;Z)V"
        }
    .end annotation

    .prologue
    .line 198
    .local p1, event:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Lcom/burstly/lib/currency/BalanceUpdateInfo;>;"
    iget-object v3, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mListeners:Ljava/util/List;

    invoke-interface {v3}, Ljava/util/List;->isEmpty()Z

    move-result v3

    if-nez v3, :cond_0

    .line 200
    :try_start_0
    iget-object v3, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mListeners:Ljava/util/List;

    invoke-interface {v3}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, i$:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_0

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/burstly/lib/feature/currency/ICurrencyListener;

    .line 201
    .local v2, listener:Lcom/burstly/lib/feature/currency/ICurrencyListener;
    if-nez p2, :cond_1

    .line 202
    invoke-interface {v2, p1}, Lcom/burstly/lib/feature/currency/ICurrencyListener;->didFailToUpdateBalance(Ljava/util/Map;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 208
    .end local v1           #i$:Ljava/util/Iterator;
    .end local v2           #listener:Lcom/burstly/lib/feature/currency/ICurrencyListener;
    :catch_0
    move-exception v0

    .line 209
    .local v0, exception:Ljava/lang/Exception;
    sget-object v3, Lcom/burstly/lib/currency/request/CurrencyRequester;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v4, Lcom/burstly/lib/currency/request/CurrencyRequester;->TAG:Ljava/lang/String;

    invoke-virtual {v3, v4, v0}, Lcom/burstly/lib/util/LoggerExt;->logThrowable(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 212
    .end local v0           #exception:Ljava/lang/Exception;
    :cond_0
    return-void

    .line 204
    .restart local v1       #i$:Ljava/util/Iterator;
    .restart local v2       #listener:Lcom/burstly/lib/feature/currency/ICurrencyListener;
    :cond_1
    :try_start_1
    invoke-interface {v2, p1}, Lcom/burstly/lib/feature/currency/ICurrencyListener;->didUpdateBalance(Ljava/util/Map;)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    goto :goto_0
.end method

.method private notifySuccess(Ljava/util/Map;)V
    .locals 1
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Lcom/burstly/lib/currency/BalanceUpdateInfo;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 188
    .local p1, event:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Lcom/burstly/lib/currency/BalanceUpdateInfo;>;"
    const/4 v0, 0x1

    invoke-direct {p0, p1, v0}, Lcom/burstly/lib/currency/request/CurrencyRequester;->notifyListeners(Ljava/util/Map;Z)V

    .line 189
    return-void
.end method


# virtual methods
.method public requestBalanceReset(Lcom/burstly/lib/currency/AccountInfo;)V
    .locals 2
    .parameter "info"

    .prologue
    .line 148
    iget-object v0, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mExecutor:Ljava/util/concurrent/Executor;

    new-instance v1, Lcom/burstly/lib/currency/request/CurrencyRequester$3;

    invoke-direct {v1, p0, p1}, Lcom/burstly/lib/currency/request/CurrencyRequester$3;-><init>(Lcom/burstly/lib/currency/request/CurrencyRequester;Lcom/burstly/lib/currency/AccountInfo;)V

    invoke-interface {v0, v1}, Ljava/util/concurrent/Executor;->execute(Ljava/lang/Runnable;)V

    .line 180
    return-void
.end method

.method public requestBalanceUpdate(Lcom/burstly/lib/currency/UserAccount;Lcom/burstly/lib/currency/AccountInfo;)V
    .locals 2
    .parameter "userAccount"
    .parameter "info"

    .prologue
    .line 127
    invoke-static {p2}, Lcom/burstly/lib/currency/request/CurrencyRequester;->isThrottled(Lcom/burstly/lib/currency/AccountInfo;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 128
    invoke-virtual {p1}, Lcom/burstly/lib/currency/UserAccount;->getAllCurrencyAccounts()Ljava/util/Map;

    move-result-object v0

    invoke-static {v0}, Lcom/burstly/lib/currency/BalanceUpdateInfo;->createFrom(Ljava/util/Map;)Ljava/util/Map;

    move-result-object v0

    invoke-direct {p0, v0}, Lcom/burstly/lib/currency/request/CurrencyRequester;->notifySuccess(Ljava/util/Map;)V

    .line 139
    :goto_0
    return-void

    .line 132
    :cond_0
    iget-object v0, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mExecutor:Ljava/util/concurrent/Executor;

    new-instance v1, Lcom/burstly/lib/currency/request/CurrencyRequester$2;

    invoke-direct {v1, p0, p1, p2}, Lcom/burstly/lib/currency/request/CurrencyRequester$2;-><init>(Lcom/burstly/lib/currency/request/CurrencyRequester;Lcom/burstly/lib/currency/UserAccount;Lcom/burstly/lib/currency/AccountInfo;)V

    invoke-interface {v0, v1}, Ljava/util/concurrent/Executor;->execute(Ljava/lang/Runnable;)V

    goto :goto_0
.end method

.method public requestLinkAccount(Lcom/burstly/lib/currency/UserAccount;Lcom/burstly/lib/currency/AccountInfo;)V
    .locals 2
    .parameter "userAccount"
    .parameter "newAccount"

    .prologue
    .line 110
    iget-object v0, p0, Lcom/burstly/lib/currency/request/CurrencyRequester;->mExecutor:Ljava/util/concurrent/Executor;

    new-instance v1, Lcom/burstly/lib/currency/request/CurrencyRequester$1;

    invoke-direct {v1, p0, p1, p2}, Lcom/burstly/lib/currency/request/CurrencyRequester$1;-><init>(Lcom/burstly/lib/currency/request/CurrencyRequester;Lcom/burstly/lib/currency/UserAccount;Lcom/burstly/lib/currency/AccountInfo;)V

    invoke-interface {v0, v1}, Ljava/util/concurrent/Executor;->execute(Ljava/lang/Runnable;)V

    .line 118
    return-void
.end method
